home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 8 / Mac Magazin and MacEasy Magazine CD - Issue 08.iso / Sharewarebibliothek / Updater⁄Infos / Frontier 2.0 => 2.0.1 Upgrader / Install Files / DocServer Docs / loop < prev    next >
Text File  |  1993-02-25  |  2KB  |  41 lines

  1.  
  2. Verb    loop
  3. Syntax    loop
  4.     statements
  5. or,
  6. loop (statement1; expression; statement2)
  7.     statements
  8. Action    In its simplest form, where the loop expression is not provided, the loop statement executes its body statements repeatedly, forever. Such a loop can be terminated by a break or return statement, or by the user canceling the script.
  9.  
  10. In its more complex form, the loop statement is executed as follows:
  11. 1. statement1 is executed;
  12. 2. expression is evaluated;
  13.  
  14. As long as expression evaluates to true,
  15. 3. the body statements are executed;
  16. 4. statement2 is executed;
  17. 5. expression is re-evaluated.
  18. Examples    loop (w = window.frontmost (); w != ""; w = window.next (w))
  19.     {msg (w)}
  20. This loop iterates through all open windows, posting a message with their titles in the Main Window.
  21.  
  22. loop
  23.     if mouse.button () « user pressed the mouse
  24.         break
  25.     msg ("It's" + clock.now () + "you still haven’t clicked the mouse!")
  26. This loops until the user presses the mouse button, while posting a message of impatience.
  27. Notes    • The complex loop form is most appropriate when the three expressions work together to control the loop iterations, as in the first example above.
  28. • statement1 is executed only once; statement2 is executed after each iteration over the loop body.
  29. • If expression initially evaluates to false, the loop body (and statement2) will not be executed even once.
  30. • The action of the complex loop statement is almost identical to the following while statement:
  31.     statement1
  32.     while expression
  33.         statements
  34.         statement2
  35. However, a continue statement in the while body would not cause statement2 to be executed before the next loop iteration, as it does with the loop statement.
  36. • For simple counting loops, the for loop construct is simpler and more efficient.
  37. See Also    for
  38. while
  39. break
  40. continue
  41.